package com.lwq.nacosorderserivce.service.impl;


import com.lwq.nacosorderserivce.mapper.OrderMapper;
import com.lwq.nacosorderserivce.pojo.Order;
import com.lwq.nacosorderserivce.pojo.OrderDto;
import com.lwq.nacosorderserivce.pojo.User;
import com.lwq.nacosorderserivce.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: 陆
 * @Date: 2024/01/30/18:24
 * @Description: 订单服务类
 */

@Service("orderService")
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Override
    public OrderDto selectById(Long id) {
        Order order = orderMapper.select(id);
        User user = restTemplate.getForObject("http://user-service/user/" +order.getUserId()+"", User.class);
        OrderDto orderDto = new OrderDto();
        BeanUtils.copyProperties(order,orderDto);
        orderDto.setUser(user);
        return  orderDto;
    }
}
